import java.util.Scanner;

public class TestDay19 {


    public static void main1(String[] args) {
        //饮料
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            if (n == 0) {
                return;
            }
            int sum = 0;//
            int SumJuice = 0;//饮料总数
            int juice = 0;
            while (n / 3 != 0) {
                juice = n / 3;
                SumJuice += juice;
                n = n % 3 + juice;//空瓶数量
                if (n == 2) {
                    n++;
                }
            }
            System.out.println(SumJuice);
        }
    }

    //找出最长公共字符串
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();
        getMaxSubstr(str1,str2);

    }
    public static void getMaxSubstr(String s1,String s2){
        //创建两个数组,
        //保证array1的长度是短的
        char[]array1 = null;
        char[]array2 = null;
        if(s1.length() < s2.length()){
            array1 = s1.toCharArray();
            array2 = s2.toCharArray();
        }else {
            array1 = s2.toCharArray();
            array2 = s1.toCharArray();
        }
        int len1 = array1.length;
        int len2 = array2.length;
        int max = 0;//记录最大值
        int start = 0;//记录起始位置
        int[][]p = new int[len1+1][len2+1];
        for (int i = 1; i <=array1.length ; i++) {

            for (int j = 1; j <=array2.length ; j++) {
                //如果两个相等
                if(array1[i-1] == array2[j-1]){
                    p[i][j] = p[i-1][j-1]+1;
                }
                if(p[i][j] > max){
                    //记录最大值
                    max = p[i][j];
                    start = i-max;
                }
            }
        }
        for (int i = start; i < max+start; i++) {
            System.out.print(array1[i]);
        }


    }

}
